package com.talkyun.utils.para;

import com.thoughtworks.paranamer.Paranamer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.StandardReflectionParameterNameDiscoverer;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class SpringImplParanamer implements Paranamer {
    private final ParameterNameDiscoverer discoverer = new StandardReflectionParameterNameDiscoverer();

    @Override
    public String[] lookupParameterNames(AccessibleObject ao) {
        if (ao instanceof Method) {
            return discoverer.getParameterNames((Method) ao);
        }
        if (ao instanceof Constructor) {
            return discoverer.getParameterNames((Constructor<?>) ao);
        }
        return EMPTY_NAMES;
    }

    @Override
    public String[] lookupParameterNames(AccessibleObject ao, boolean b) {
        return lookupParameterNames(ao);
    }
}
